home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / selfile.zip / SELFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  30KB  |  945 lines

  1. {  
  2.    +--------------------------------------------------------------+
  3.    |                                                              |
  4.    |  Unit:    Selfile     Version: 3.0                           |
  5.    |                                                              |
  6.    |  Copyright (c) 1988   Repstad Computer Consultants           |
  7.    |                       RFD #1, Box 3720                       |
  8.    |                       Sheldon, VT 05483                      |
  9.    |                       (802) 933-5133 (Voice)                 |
  10.    |                       (802) 933-2417 (Data - Black Creek BBS)|
  11.    |                                                              |  
  12.    |  All Rights Reserved                                         |
  13.    |                                                              |
  14.    |  This TP4.0 Unit is shareware...a $10.00 contribution is     |
  15.    |  suggested. See Selfile.Doc for more info on this unit.      |
  16.    |                                                              |
  17.    |                                                              |
  18.    +--------------------------------------------------------------+
  19. }
  20.  
  21.  
  22.  
  23.  
  24. unit selfile;
  25.  
  26. Interface
  27.  
  28. Uses  Crt,Dos;
  29.  
  30. {  
  31.    +----------------------------------------------------+
  32.    | Define interface functions/procedures              |
  33.    +----------------------------------------------------+
  34. }
  35.  
  36.    function Sel_File(Var Fil_Nam : String; title, path : String; 
  37.                      attribute   : byte) : Integer;
  38.  
  39.    procedure SetLim(rowb,
  40.                     colb,
  41.                     rowq,
  42.                     colq,
  43.                     active,
  44.                     inactive,
  45.                     boarder      : Integer);
  46.  
  47.  
  48. {  
  49.    +----------------------------------------------------+
  50.    | Begin Unit Implementation                          |
  51.    +----------------------------------------------------+
  52. }
  53.  
  54. Implementation
  55.  
  56. {  
  57.    +----------------------------------------------------+
  58.    | Define data types for unit                         |
  59.    +----------------------------------------------------+
  60. }
  61.  
  62. Type   
  63.  
  64.    Fptr    = ^File_Rec;
  65.  
  66.    File_Rec = Record
  67.        Filnam  : String[12];
  68.        Next    : Fptr;
  69.        Prev    : Fptr;
  70.    End;
  71.  
  72.    sstr_type = string[12];
  73.  
  74. {  
  75.    +----------------------------------------------------+
  76.    | Define constants for unit                          |
  77.    +----------------------------------------------------+
  78. }
  79.  
  80. Const
  81.  
  82.    LHIGHLITE = 112;                       { Black w/ White Background      }
  83.    LNORMAL   =  31;                       { White w/ Blue Background       }
  84.    DEF_BDR   =   1;                       { Default boarder = double line  }
  85.                                           { Boarder types are:
  86.                                                 0  = No boarder
  87.                                                 1  = Double line
  88.                                                 2  = Single Line
  89.                                                 3  = +-| chars             }
  90.  
  91. {  
  92.    +----------------------------------------------------+
  93.    | Define Globals for unit                            |
  94.    +----------------------------------------------------+
  95. }
  96.  
  97. Var
  98.  
  99.    Row_Begin   :  Integer;             { Absolute screen Row/Col for       }
  100.    Col_Begin   :  Integer;             { location of Upper Left Corner     }
  101.                                        { of file selection window          }
  102.    Row_Quan    :  Integer;             { Number of rows                    }
  103.    Col_Quan    :  Integer;             { Number of cols                    }
  104.    Act_Attr    :  Integer;             { Active (highlighted) file vid attr}
  105.    IAct_Attr   :  Integer;             { Inactive file video attribute     }
  106.    Save_Attr   :  Integer;             { Save current text attribute       }
  107.    Wndw_Bdr    :  Integer;             { File selection window boarder type}
  108.    F_Col_Max   :  Integer;             { Max Col to put file name at       }
  109.    F_Row_Max   :  Integer;             { Max Row to put file name at       }
  110.    Cur_Col     :  Integer;             { Current column                    }
  111.    Cur_Row     :  Integer;             { Current Row                       }
  112.    Row_Beg     :  Integer;             { Beginning row of window           }
  113.    Col_Beg     :  Integer;             { Beginning col of window           }
  114.  
  115.    Save_WMin   :  Word;                { Save area for WindMin & WindMax   }
  116.    Save_WMax   :  Word;   
  117.  
  118.    HPtr        :  Pointer;             { Pointer to heap for mark/release  }
  119.  
  120.    vidc        :  Byte Absolute $B800:0000;  { Pointer to color video mem  }
  121.    vidm        :  Byte Absolute $B000:0000;  { Pointer to b/w video memory }
  122.    screen      :  Array [1..4000] of Byte;
  123.    vptr        :  Pointer;                   { screen save mem pointer     }
  124.  
  125. {  
  126.    +----------------------------------------------------+
  127.    | Begin Unit SelFile Procedures                      |
  128.    +----------------------------------------------------+
  129. }
  130. {  
  131.    +----------------------------------------------------+
  132.    | Procedure beepit                                   |
  133.    +----------------------------------------------------+
  134. }
  135.  
  136. Procedure beepit;
  137. Begin
  138.    sound(440);                               { Beep the speaker            }
  139.    delay(200);
  140.    nosound;
  141. end;
  142. {  
  143.    +----------------------------------------------------+
  144.    | Function ISCOLOR                                   |
  145.    +----------------------------------------------------+
  146. }
  147.  
  148. Function ISCOLOR : Boolean;
  149.  
  150. Var
  151.    regs        : Registers;
  152.    video_mode  : Integer;
  153.    equ_lo      : Byte;
  154.  
  155. Begin
  156.    Intr($11,regs);                              { Determin video type      }
  157.    video_mode := regs.al AND $30;
  158.    video_mode := video_mode SHR 4;
  159.    Case video_mode of
  160.       1  :  ISCOLOR := FALSE;
  161.       2  :  ISCOLOR := TRUE;
  162.    End;
  163. End;
  164. {  
  165.    +----------------------------------------------------+
  166.    | Procedure Highlight                                |
  167.    +----------------------------------------------------+
  168. }
  169.  
  170. Procedure Highlight(ptr : Fptr);
  171.  
  172. Begin
  173.  
  174.    TextAttr := Act_Attr;                     { Highlight a file name       }
  175.    GoToXY(Cur_Col-1,Cur_Row);
  176.    Write('',ptr^.filnam,'');
  177.    TextAttr := IAct_Attr;
  178. End;
  179. {  
  180.    +----------------------------------------------------+
  181.    | Procedure Un_Highlight                             |
  182.    +----------------------------------------------------+
  183. }
  184.  
  185. Procedure Un_Highlight(ptr : Fptr);
  186.  
  187. Begin
  188.  
  189.    TextAttr := IAct_Attr;                    { Un-Highlight a file name    }
  190.    GoToXY(Cur_Col-1,Cur_Row);
  191.    Write(' ',ptr^.filnam,' ');
  192. End;
  193.  
  194. {  
  195.    +----------------------------------------------------+
  196.    | Procedure Save_Screen                              |
  197.    +----------------------------------------------------+
  198. }
  199.  
  200. Procedure Save_Screen;
  201.  
  202. Begin
  203.  
  204.    Save_WMin := WindMin;                        { Save the current window  }
  205.    Save_WMax := WindMax;                        { min/max coordinates      }
  206.    Save_Attr := TextAttr;
  207.  
  208.    If (NOT ISCOLOR) Then                        { Move screen image to     }
  209.       Move(vidm,screen,4000)                    { Heap depending on video  }
  210.    Else                                         { Card Type                }
  211.       Move(vidc,screen,4000);
  212. End;
  213.  
  214. {  
  215.    +----------------------------------------------------+
  216.    | Procedure Restore_Screen                           |
  217.    +----------------------------------------------------+
  218. }
  219.  
  220. Procedure Restore_Screen;
  221. Begin;
  222.  
  223.    WindMin := Save_WMin;                        { Restore original window  }
  224.    WindMax := Save_WMax;                        { min/max coordinates      }
  225.    TextAttr := Save_Attr;
  226.  
  227.    If (NOT ISCOLOR) Then                        { Restore original screen  }
  228.       Move(screen,vidm,4000)                    { image from the Heap      }
  229.    Else
  230.       Move(screen,vidc,4000);
  231. End;
  232.  
  233. {  
  234.    +----------------------------------------------------+
  235.    | Procedure Cursor                                   |
  236.    +----------------------------------------------------+
  237. }
  238.  
  239. Procedure Cursor(attrib : Boolean);
  240. Var
  241.  
  242.    regs : Registers;
  243.  
  244. Begin
  245.  
  246.    If (NOT attrib) Then                         { Turn cursor on/off       }
  247.    Begin
  248.       regs.ah := 1;
  249.       regs.cl := 7;
  250.       regs.ch := 32;
  251.       Intr($10,regs);
  252.    End
  253.    Else
  254.    Begin
  255.       Intr($11,regs);
  256.       regs.cx := $0607;
  257.       If ((regs.al AND $10) <> 0) Then
  258.          regs.cx := $0B0C;
  259.       regs.ah := 1;
  260.       Intr($10,regs);
  261.    End;
  262. End;
  263.  
  264. Procedure Wchars(ch : char; attr : byte; count : Integer);
  265.  
  266. Type
  267.    bchar = record
  268.       case byte of
  269.       0 : (bbyte : byte);
  270.       1 : (cchar : char);
  271.    end;
  272.  
  273. Var
  274.  
  275.    Regs  :  Registers;
  276.    temp  :  bchar;
  277. Begin
  278.  
  279.    temp.cchar := ch;                            { Write a char to screen   }
  280.    regs.ah := $09;                              { without any scrolling    }
  281.    regs.al := temp.bbyte;                       { this is here so we can   }
  282.    regs.bh := 0;                                { write to the last row/col}
  283.    regs.bl := attr;                             { in the window without    }
  284.    regs.cx := count;                            { scrolling it!            }
  285.    Intr($10,regs);
  286.  
  287. End;
  288. Procedure Disp_SStr(sstr : String; Index : Integer);
  289. Var
  290.  
  291.    T1,T2,T3 : Char;
  292.    I        : Integer;
  293.    irow     : Integer;
  294.    ch       : char;
  295.    swmin,swmax : Word;
  296.    swatt    : Integer;
  297.  
  298.  
  299. Begin
  300.  
  301.    Case Wndw_Bdr of
  302.       1  :  Begin
  303.                T1 := '╡';
  304.                T2 := '╞';
  305.                T3 := '═';
  306.             End;
  307.       2  :  Begin
  308.                T1 := '┤';
  309.                T2 := '├';
  310.                T3 := '─';
  311.             End;
  312.       3  :  Begin
  313.                T1 := '|';
  314.                T2 := '|';
  315.                T3 := '-';
  316.             End;
  317.    End;
  318.  
  319.    SWMin := WindMin;                        { Save the current window  }
  320.    SWMax := WindMax;                        { min/max coordinates      }
  321.    Swatt := TextAttr;
  322.  
  323.    WindMin := Save_WMin;
  324.    WindMax := Save_Wmax;
  325.  
  326.    gotoxy(Col_Begin+2,Row_Begin+Row_Quan-1);
  327.    TextAttr := IAct_Attr;
  328.    if (Index <= 0) then
  329.       Wchars(t3,Iact_attr,6)  { Erase any existing search string stuff }
  330.    else begin
  331.       Write(T1);
  332.       TextAttr := Act_Attr;
  333.       Write(' ',sstr,' ');
  334.       TextAttr := IAct_Attr;
  335.       Write(t2);
  336.       Wchars(t3,Iact_attr,2); { erase old '├' end marker... }
  337.    end;
  338.    WindMin := SWMin;
  339.    WindMax := SWmax;
  340.    TextAttr:= SWAtt;
  341. End;
  342.  
  343.  
  344. {  
  345.    +----------------------------------------------------+
  346.    | Draw_Boarder                                       |
  347.    +----------------------------------------------------+
  348. }
  349.  
  350. Procedure Draw_Boarder(str : string);
  351. Var
  352.  
  353.    ULC   : Char;
  354.    URC   : Char;
  355.    LRC   : Char;
  356.    LLC   : Char;
  357.    HLINE : Char;
  358.    VLINE : Char;
  359.    TLFT  : Char;
  360.    TRHT  : Char;
  361.    I     : Integer;
  362.  
  363. Begin
  364.  
  365.    Case (Wndw_Bdr) of                        { define boarder elements     }
  366.                                              { based on global Wndw_Bdr    }
  367.       1  :  Begin
  368.  
  369.                ULC := '╔';
  370.                URC := '╗';
  371.                LRC := '╝';
  372.                LLC := '╚';
  373.                HLINE := '═';
  374.                VLINE := '║';
  375.                TLFT := '╡';
  376.                TRHT := '╞';
  377.  
  378.             End;
  379.  
  380.       2  :  Begin
  381.  
  382.                ULC := '┌';
  383.                URC := '┐';
  384.                LRC := '┘';
  385.                LLC := '└';
  386.                HLINE := '─';
  387.                VLINE := '│';
  388.                TLFT := '┤';
  389.                TRHT := '├';
  390.  
  391.             End;
  392.  
  393.       3  :  Begin
  394.  
  395.                ULC := '+';
  396.                URC := '+';
  397.                LRC := '+';
  398.                LLC := '+';
  399.                HLINE := '-';
  400.                VLINE := '|';
  401.                TLFT := '|';
  402.                TRHT := '|';
  403.  
  404.             End;
  405.  
  406.    End; {Case}
  407.  
  408.    gotoxy(1,1);                                 { Draw the boarder         }
  409.    write(ULC);
  410.    For i := 1 to (Col_Quan *15 +3) Do
  411.       write(HLINE);
  412.    write(URC);
  413.    For i := 2 to Row_Quan -1 Do
  414.    begin
  415.       gotoxy(1,i);
  416.       write(VLINE);
  417.       gotoxy((Col_Quan*15 + 5),i);
  418.       write(VLINE);
  419.    end;
  420.    gotoxy(1,Row_Quan);
  421.    write(LLC);
  422.    for i:=1 to (col_Quan*15+3) Do
  423.       write(HLINE);
  424.    wchars(LRC,IAct_Attr,1);
  425.  
  426.                                              { Put title on screen if it   }
  427.                                              { will fit                    }
  428.    if ((length(str) <> 0) And ((Length(str)+4) < (Col_Quan*15+3))) then
  429.    begin
  430.       gotoxy(3,1);
  431.       write(TLFT,' ',str,' ',TRHT);
  432.    end;
  433. End;
  434.  
  435. {
  436.    +----------------------------------------------------+
  437.    | Procedure Make_Window                              |
  438.    +----------------------------------------------------+
  439. }
  440.  
  441.  
  442. Procedure Make_Window(title : String);
  443.  
  444. Var
  445.    x1,y1,x2,y2 : Byte;
  446.    ch          : char;
  447.  
  448. Begin
  449.  
  450.    Save_Screen;                              { Save the current screen     }
  451.    TextAttr := IAct_Attr;                    { Define text color           }
  452.  
  453.    x1 := Col_Begin;                          { Define files window         }
  454.    y1 := Row_Begin;
  455.    x2 := Col_Begin + (Col_Quan * 15) + 4;
  456.    y2 := Row_Begin + Row_Quan - 1;
  457.    Window(x1,y1,x2,y2);                      { Activate the window         }
  458.    ClrScr;                                   { Clear window to IAct_Attr   }
  459.    If (Wndw_bdr <> 0) then
  460.    begin
  461.       Draw_Boarder(Title);                   { Draw the window boarder     }
  462.       x1 := x1 + 1;                          { Redefine window so we don't }
  463.       x2 := x2 - 1;                          { scroll the boarder if there }
  464.       y1 := y1 + 1;                          { is one                      }
  465.       y2 := y2 - 1;
  466.    End;
  467.    Window(x1,y1,x2,y2);                      { Activate the window         }
  468.    ClrScr;                                   { Clear window to IAct_Attr   }
  469. End;
  470. {
  471.    +----------------------------------------------------+
  472.    | Function Get_Files                                 |
  473.    +----------------------------------------------------+
  474. }
  475.  
  476. Function Get_Files(path : String; attr : Byte; Var First : Fptr) : Integer;
  477.  
  478. Var
  479.  
  480.    p1,p2   :   Fptr;
  481.    p3,p4   :   Fptr;
  482.    nbrfils :   Integer;
  483.    finfo   :   SearchRec;
  484.    placefound :boolean;
  485.  
  486. Begin
  487.  
  488.    Get_Files := 0;
  489.    FindFirst(path,attr,finfo);            { Find first matching file       }
  490.    
  491.    If DosError = 0 then                   { If we found a file... continue }
  492.    begin
  493.        new(p1);                           { allocate pointer to file name  }
  494.        First := p1;                       { save a copy of it in First     }
  495.        p1^.prev := nil;                   { set up prev/next pointers      }
  496.        p1^.next := nil;
  497.        p1^.filnam := finfo.name;          { copy in filename               }
  498.        p2 := p1;                          { temp copy of ptr for next/prev }
  499.        nbrfils := 1;                      { init number of files found     }
  500.  
  501.        while DosError = 0 Do              { get any additional files       }
  502.        begin
  503.  
  504.            FindNext(finfo);               { find next matching file        }
  505.            if (DosError = 0) then         { if there are more continue     }
  506.            begin
  507.                nbrfils := nbrfils + 1;    { increment number files counter }
  508.                new(p1);                   { allocate new pointer           }
  509.                p1^.filnam := finfo.name;  { copy in file name              }
  510.                p1^.next := Nil;
  511.                if (p1^.filnam < First^.filnam) Then begin
  512.                   p1^.next := First;
  513.                   First^.prev := p1;
  514.                   First := p1;
  515.                   end
  516.                else begin
  517.                   p2 := First;
  518.                   placefound := false;
  519.                   while ((p2^.Next <> Nil) AND (Not Placefound)) Do Begin
  520.                      if (p1^.filnam >= p2^.next^.filnam) then
  521.                         p2 := p2^.next
  522.                      else
  523.                         placefound := true;
  524.                   end;
  525.                   p1^.next := p2^.next;
  526.                   p1^.prev := p2;
  527.                   p2^.next^.prev := p1;
  528.                   p2^.next := p1;
  529.                end;
  530.            end;
  531.        end;
  532.        Get_Files := nbrfils;              { return number of files found   }
  533.    end;
  534. end;
  535.  
  536. {
  537.    +----------------------------------------------------+
  538.    | Procedure Put_Files                                |
  539.    +----------------------------------------------------+
  540. }
  541.  
  542. Procedure Put_Files (ptr : Fptr; maxfiles : integer);
  543.  
  544. Var
  545.  
  546.    ptr2  : Fptr;
  547.    i,j,k,irow,icol : integer;
  548.  
  549. Begin
  550.  
  551.    ptr2 := ptr;                              { put the files we found into }
  552.    irow := Row_Beg;                          { the files window            }
  553.    icol := Col_Beg;                          { by traversing the file ptr  }
  554.                                              { linked list                 }
  555.    For i := 1 to maxfiles do
  556.    Begin
  557.       gotoxy(icol,irow);
  558.       write(ptr2^.filnam);
  559.       icol := icol + 15;
  560.       if (icol > F_Col_Max) Then
  561.       begin
  562.          irow := irow + 1;
  563.          icol := Col_Beg;
  564.       end;
  565.       if (ptr2^.next <> nil) Then
  566.          ptr2 := ptr2^.next
  567.       else
  568.          i := maxfiles;
  569.    end;
  570. end;
  571.  
  572. {  
  573.    +----------------------------------------------------+
  574.    | Function Srch_Dir                                  |
  575.    +----------------------------------------------------+
  576. }
  577.  
  578. Function Srch_Dir( ptr : Fptr; index : integer; sstr : sstr_type) : Fptr;
  579.  
  580. Var
  581.    ptr1        :  Fptr;
  582.    found,done  :  boolean;
  583.    i           :  integer;
  584.    str1,str2   :  string[12];
  585.  
  586. Begin
  587.  
  588.    ptr1 := ptr;
  589.    found := false;
  590.    done := false;
  591.    str1 := sstr;
  592.    Srch_dir := Nil;
  593.    While ((ptr1 <> Nil) And (Not Found)) Do Begin
  594.       str2 := copy(ptr1^.filnam,1,index);
  595.       if str1 = str2 then begin
  596.          found := true;
  597.          Srch_Dir := Ptr1;
  598.       End
  599.       else
  600.          ptr1 := ptr1^.next;
  601.    End;
  602. End;
  603. {
  604.    +----------------------------------------------------+
  605.    | Function Prev_File                                 |
  606.    +----------------------------------------------------+
  607. }
  608.  
  609. Function Prev_File( ptr : Fptr; count : integer) : Fptr;
  610.  
  611. Var
  612.  
  613.    ptr2,ptr3   : Fptr;
  614.    i,j,k,col2  : integer;
  615.  
  616. Begin
  617.  
  618.    ptr2 := ptr;                                 { back up one file         }
  619.    j := count;
  620.    if (ptr2^.prev <> nil) then                  { is there a prev file?    }
  621.    begin
  622.       Un_Highlight(ptr2);                       { unhighlight current file }
  623.       for i := 1 to j do                        { traverse file list while }
  624.       begin                                     { updating the current row }
  625.          if (ptr2^.prev <> nil) Then            { and col locs.            }
  626.          begin
  627.             ptr2 := ptr2^.prev;
  628.             cur_col := cur_col - 15;
  629.             if (cur_col < col_beg) then
  630.             begin
  631.                cur_col := F_Col_Max;
  632.                Cur_Row := Cur_Row - 1;
  633.                if (Cur_Row < Row_Beg) Then
  634.                Begin                            { desired file not in wndw }
  635.                   Cur_Row := Row_Beg;           { scroll the display and   }
  636.                   GoToXY(1,1);                  { write out the new files  }
  637.                   InsLine;
  638.                   ptr3 := ptr2;
  639.                   col2 := cur_col;
  640.                   for k := 1 to Col_Quan do
  641.                   begin
  642.                      gotoxy(col2,Cur_Row);
  643.                      write(ptr3^.filnam);
  644.                      if (ptr3^.prev <> Nil) Then
  645.                      begin
  646.                         ptr3 := ptr3^.prev;
  647.                         col2 := col2 - 15;
  648.                      end;
  649.                   end;
  650.                end;
  651.             end;
  652.          end
  653.          else
  654.             i := count;
  655.       end;
  656.       highlight(ptr2);                             { all done, highlight   }
  657.    end                                             { new current filename  }
  658.    else
  659.       beepit;
  660.    prev_file := ptr2;
  661. end;
  662.  
  663. {
  664.    +----------------------------------------------------+
  665.    | Function Next_File                                 |
  666.    +----------------------------------------------------+
  667. }
  668.  
  669. Function Next_File( ptr : Fptr; count : integer) : Fptr;
  670.  
  671. Var
  672.  
  673.    ptr2,ptr3   : Fptr;
  674.    i,j,k,col2  : integer;
  675.  
  676. Begin
  677.  
  678.    ptr2 := ptr;                              { same as prev_file but in    }
  679.    j := count;                               { other direction             }
  680.    if (ptr2^.Next <> nil) then
  681.    begin
  682.       Un_Highlight(ptr2);
  683.       for i := 1 to j do
  684.       begin
  685.          if (ptr2^.Next <> nil) Then
  686.          begin
  687.             ptr2 := ptr2^.Next;
  688.             cur_col := cur_col + 15;
  689.             if (cur_col > F_Col_Max) then
  690.             begin
  691.                cur_col := Col_Beg;
  692.                Cur_Row := Cur_Row + 1;
  693.                if (Cur_Row > F_Row_Max) then
  694.                Begin
  695.                   Cur_Row := F_Row_Max;
  696.                   GoToXY(1,1);
  697.                   DelLine;
  698.                   ptr3 := ptr2;
  699.                   col2 := cur_col;
  700.                   for k := 1 to Col_Quan do
  701.                   begin
  702.                      gotoxy(col2,Cur_Row);
  703.                      write(ptr3^.filnam);
  704.                      if (ptr3^.Next <> Nil) Then
  705.                      begin
  706.                         ptr3 := ptr3^.Next;
  707.                         col2 := col2 + 15;
  708.                      end;
  709.                   end;
  710.                end;
  711.             end;
  712.          end
  713.          else
  714.             i := count;
  715.       end;
  716.       highlight(ptr2);
  717.    end
  718.    else
  719.       beepit;
  720.    Next_file := ptr2;
  721. end;
  722.  
  723. {
  724.    +----------------------------------------------------+
  725.    | Procedure SetLim                                   |
  726.    +----------------------------------------------------+
  727. }
  728.  
  729.  
  730.  
  731. Procedure SetLim;
  732.  
  733. Var
  734.  
  735.    Bad_Parms   :  Boolean;
  736.  
  737. Begin
  738.  
  739.    Bad_Parms := FALSE;                          { Allow the user to define }
  740.                                                 { the location and limits  }
  741.    if ((rowb < 1) OR (rowb > 25)) Then          { of the file selection    }
  742.       Bad_Parms := TRUE;                        { window. Make sure parms  }
  743.    if ((colb < 1) OR (colb > 65)) Then          { are within tolerable     }
  744.       Bad_Parms := TRUE;                        { limits before we accept  }
  745.    if ((rowq < 1) OR (rowb+rowq > 25)) Then     { them.                    }
  746.       Bad_Parms := TRUE;
  747.    if ((colq < 1) OR (colb+colq > 80)) Then
  748.       Bad_Parms := TRUE;
  749.    if ((active < 0) OR (active > 255)) Then
  750.       Bad_Parms := TRUE;
  751.    if ((inactive < 0) OR (inactive > 255)) Then
  752.       Bad_Parms := TRUE;
  753.    if ((boarder < 0) OR (boarder > 3)) Then
  754.       Bad_Parms := TRUE;
  755.  
  756.    if (Bad_Parms = FALSE) Then                  { Parms ok...update our    }      
  757.    Begin                                        { global variables         }
  758.       Row_Begin := rowb;        
  759.       Col_Begin := colb;
  760.       Row_Quan  := rowq;
  761.       Col_Quan  := colq;
  762.       Act_Attr  := active;
  763.       IAct_Attr := inactive;
  764.       Wndw_Bdr  := boarder;
  765.    End;
  766. End;
  767.  
  768. {
  769.    +----------------------------------------------------+
  770.    | Function Sel_File                                  |
  771.    +----------------------------------------------------+
  772. }
  773.  
  774.  
  775. Function Sel_File;
  776.  
  777. Var
  778.  
  779.    FFile       :  Fptr;
  780.    ptr1        :  Fptr;
  781.    ptr2        :  Fptr;
  782.    ptr3        :  Fptr;
  783.    ptr4        :  Fptr;
  784.    hptr        :  Pointer;
  785.    indx        :  Integer;
  786.    RC          :  String[3];
  787.    iopt        :  Integer;
  788.    Max_Files   :  Integer;
  789.    Max_Scrn    :  Integer;
  790.    Col_Offset  :  Integer;
  791.    ch          :  char;
  792.    done        :  boolean;
  793.    temp        :  Integer;
  794.    Sindex      :  Integer;
  795.    SSTR        :  sstr_type;
  796.  
  797.  
  798. Begin { Procedure Sel_File }
  799.                                           { save the current heap Pointer  }
  800.    New(hptr);
  801.    Mark(hptr);
  802.    sstr := '';
  803.    sindex := 0;
  804.    Max_Files := Get_Files(path, attribute, FFile);{ get matching files     }
  805.    if (Max_Files <> 0) then               { proceed if we found files      }
  806.    begin
  807.       Col_Beg := 3;                       { define some window limits      }
  808.       Row_Beg := 1;
  809.       F_Col_Max := (Col_Beg + ((Col_Quan - 1) * 15));
  810.       If (Wndw_Bdr <> 0) Then             { Compute Max rows of files      }
  811.          F_Row_Max := Row_Quan - 2
  812.       Else
  813.          F_Row_Max := Row_Quan;
  814.       ptr1 := FFile;                         
  815.       Max_Scrn := Col_Quan * F_Row_Max;   { Compute Max files within wndw  }
  816.       if (Max_Scrn > Max_Files) Then Max_Scrn := Max_Files;
  817.       Cursor(FALSE);                      { Turn off the cursor            }
  818.       make_window(Title);                 { Draw the files window          }
  819.  
  820.       Put_Files(ptr1,Max_Scrn);           { fill window w/ avail files     }
  821.       Cur_Row := Row_Beg;                 { init cur row/col               }
  822.       Cur_Col := Col_Beg;
  823.       Highlight(ptr1);                    { highlight first file           }
  824.  
  825.       Done := False;                      { continue till user selects a   }
  826.       While (Not Done) Do                 { file or quits                  }
  827.       Begin
  828.          ch := ReadKey;
  829.          if (ch = #0) then begin
  830.             ch := ReadKey;
  831.             case ch of
  832.  
  833.                #75 : ptr1 := prev_file(ptr1,1);       { Left Arrow         }
  834.                #77 : ptr1 := next_file(ptr1,1);       { Right Arrow        }
  835.                #72 : ptr1 := prev_file(ptr1,Col_Quan);{ Up Arrow           }
  836.                #80 : ptr1 := next_file(ptr1,Col_Quan);{ Down Arrow         }
  837.                #73 : ptr1 := prev_file(ptr1,Max_Scrn);{ Page Up            }
  838.                #81 : ptr1 := next_file(ptr1,Max_Scrn);{ Page Down          }
  839.                #59 : Begin
  840.                      Sel_File := 2;
  841.                      Fil_Nam := '';
  842.                      Done := True;
  843.                   End;
  844.             end;
  845.          End
  846.          Else
  847.          Begin
  848.  
  849.             Case ch of
  850.                #13 : begin                            { Return Key         }
  851.                         Fil_Nam := ptr1^.filnam;      { return highlighted }
  852.                         Sel_File := 1;
  853.                         Done := True;                 { file to caller     }
  854.                      end;
  855.                #27 : begin                            { Escape             }
  856.                         sel_file := 0;                { user quit          }
  857.                         Fil_Nam := '';
  858.                         Done := True;
  859.                      End;
  860.                #8  : begin
  861.                         Sindex := Sindex - 1;
  862.                         if (Sindex <= 0) Then begin
  863.                            Sindex := 0;
  864.                            sstr := '';
  865.                         end
  866.                         else
  867.                            sstr := copy(sstr,1,sindex);
  868.                      End;
  869.                Else Begin
  870.  
  871.                   ch := upcase(ch);
  872.                   If ((ch > #32) and (ch < #127)) then begin
  873.                      SIndex := Sindex + 1;
  874.                      If (Sindex > 12) Then
  875.                         Sindex := 12
  876.                      Else
  877.                         sstr := concat(sstr,ch);
  878.                   End;
  879.                End;
  880.             end;
  881.             Disp_sstr(sstr,sindex);
  882.             If (Sindex <> 0) then begin
  883.                ptr3 := Srch_Dir(FFile,Sindex,SSTR);
  884.                if (ptr3 = Nil) Then
  885.                   beepit
  886.                else begin
  887.                   If (ptr3 = FFile) Then Begin
  888.                      While(ptr1 <> ptr3) Do 
  889.                         ptr1 := Prev_File(Ptr1,1);
  890.                   End
  891.                   Else Begin
  892.  
  893.                      ptr4 := FFile;
  894.                      While (ptr4 <> ptr3) Do Begin
  895.                         if (ptr4 = ptr1) Then Begin { found cur file before sfile}
  896.                            While(ptr1 <> ptr3) Do Begin
  897.                               ptr1 := next_file(ptr1,1);
  898.                               ptr4 := ptr1;
  899.                            end;
  900.                         end
  901.                         else begin
  902.                            ptr4 := ptr4^.next;
  903.                            if (ptr4 = ptr3) Then Begin { found sfile before cur file}
  904.                               While(ptr1 <> ptr3) Do Begin
  905.                                  ptr1 := prev_file(ptr1,1);
  906.                               end;
  907.                            end;
  908.                         end;
  909.                      end;
  910.                   End;
  911.                end;
  912.             end;
  913.          End;
  914.       end;
  915.       Restore_Screen;                     { restore the screen             }
  916.  
  917.    end
  918.    else
  919.    begin
  920.       Sel_File := -1;                     { no files found...return null   }
  921.       Fil_Nam := '';
  922.    End;
  923.    Release(hptr);                         { restore all mem allocated      }
  924.    Cursor(True);                          { turn cursor back on            }
  925. end;
  926. {
  927.    +----------------------------------------------------+
  928.    | Define Unit Initialization Section                 |
  929.    +----------------------------------------------------+
  930. }
  931.  
  932. Begin
  933.  
  934.    Row_Begin := 1;                        { Define default file selection  }
  935.    Col_Begin := 1;                        { window as the entire screen    }
  936.    Row_Quan  := 24;
  937.    Col_Quan  := 5;
  938.    Act_Attr  := LHIGHLITE;                { Define default video attributes}
  939.    IAct_Attr := LNORMAL;
  940.    Wndw_Bdr  := DEF_BDR;
  941.  
  942.  
  943. end.
  944.  
  945.